<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
    <head>
        <th:block th:include="include :: header('添加知识库类别')"/>
    </head>
    <body class="white-bg">
        <div class="wrapper wrapper-content animated fadeInRight ibox-content">
            <form class="form-horizontal m" id="form-category-add">
                <input id="treeId" name="codeparent" type="hidden" th:value="${cate.codeparent}"/>
                <div class="form-group">
                    <label class="col-sm-3 control-label">父类类别：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input class="form-control" type="text" onclick="selectCateTree()" id="codeparent"
                                   readonly="true" th:value="${cate.sortname}">
                            <span class="input-group-addon">
                                <i class="fa fa-search"></i>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">类别编号：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="codepk" id="codePk" required>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">类别名称：</label>
                    <div class="col-sm-8">
                        <input id="sortName" name="sortname" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">层次：</label>
                    <div class="col-sm-8">
                        <input readonly="true" name="layernum" class="form-control" th:value="${cate.layernum}==-1?1:${cate.layernum}+1" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">显示排序：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="ordnum" required>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea id="remark" name="remark" class="form-control" type="text" style="height: 70px;"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-refresh" title="是否结束">结束标记：
                        <i class="fa fa-question-circle-o"></i>
                    </label>
                    <div class="col-sm-3 is-refresh">
                        <div class="radio-box">
                            <input type="radio" id="endflag-no" name="endflag" value="1" checked>
                            <label for="endflag-no">否</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" id="endflag-yes" name="endflag" value="0">
                            <label for="endflag-yes">是</label>
                        </div>
                    </div>
                </div>
                <div class="col-sm-offset-3">
                    <span class="help-block m-b-none" style="color: red;margin-left: 10px;">
                        <i class="fa fa-info-circle"></i>
                           填写说明：<br>
                                  a、此处新增由开发人员完成，请不要擅自增加；<br>
                                  b、“分类编号”：一但录入系统，不建议进行修改；<br>
                                  c、“显示排序”：对相同层次进行排序，建议采用有规律的数字；
                    </span>
                </div>
            </form>
        </div>
        <th:block th:include="include :: footer"/>
        <script>
            var prefix = ctx + "system/kbm/category";

            /*菜单管理-新增-选择菜单树*/
            function selectCateTree() {
                var treeId = $("#treeId").val();
                var codepk = treeId > 0 ? treeId : 1;
                var url = prefix + "/selectCateTree/" + codepk;
                var options = {
                    title: '类别选择',
                    width: "380",
                    url: url,
                    callBack: doSubmit
                };
                $.modal.openOptions(options);
            }

            $("#form-category-add").validate({
                onkeyup: false,
                rules: {
                    codepk: {
                        remote: {
                            url: prefix + "/checkCodePkUnique",
                            type: "post",
                            dataType: "json",
                            data: {
                                "codeparent": function () {
                                    return $("input[name='codeparent']").val();
                                },
                                "codepk": function () {
                                    return $.common.trim($("#codePk").val());
                                }
                            },
                            dataFilter: function (data, type) {
                                return $.validate.unique(data);
                            }
                        },
                    },
                    sortname: {
                        remote: {
                            url: prefix + "/checkSortNameUnique",
                            type: "post",
                            dataType: "json",
                            data: {
                                "codeparent": function () {
                                    return $("input[name='codeparent']").val();
                                },
                                "sortname": function () {
                                    return $.common.trim($("#sortName").val());
                                }
                            },
                            dataFilter: function (data, type) {
                                return $.validate.unique(data);
                            }
                        },
                    }
                },
                messages: {
                    "codepk": {
                        remote: "该类别编号已经存在"
                    },
                    "sortname":{
                        remote: "该类别已存在"
                    }
                },
                focusCleanup: true
            });

            function submitHandler() {
                var codeparent = $("#treeId").val();
                $("#treeId").val(codeparent == 0 ? -1 : [[${cate.codepk}]])
                if ($.validate.form()) {
                    $.operate.save(prefix + "/kbmCateAdd", $('#form-category-add').serialize());
                }
            }

            function doSubmit(index, layero) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        </script>
    </body>
</html>
